// 本地模拟API - 不需要服务器，直接在小程序中运行
const localMockApi = {
  // 模拟用户数据
  mockUser: {
    id: 1001,
    openid: 'mock_openid',
    nickname: '测试用户',
    avatar: 'http://192.168.100.102:8080/icons/AIPortrait.png',
    phone: '',
    vipLevel: 0,
    points: 1000,
    vipExpireTime: null,
    createdAt: new Date().toISOString()
  },

  // 模拟聊天历史
  mockChatHistory: [],

  // 模拟微信登录
  async wechatLogin(loginData) {
    return new Promise((resolve) => {
      setTimeout(() => {
        const token = 'mock_token_' + Date.now();
        resolve({
          code: 200,
          message: '登录成功',
          data: {
            token: token,
            user: this.mockUser
          }
        });
      }, 500); // 模拟网络延迟
    });
  },

  // 模拟获取用户信息
  async getUserInfo() {
    return new Promise((resolve) => {
      setTimeout(() => {
        resolve({
          code: 200,
          message: '获取成功',
          data: this.mockUser
        });
      }, 300);
    });
  },

  // 模拟AI聊天
  async chat(chatData) {
    return new Promise((resolve) => {
      setTimeout(() => {
        const responses = {
          'general': '这是一个通用AI对话的模拟回复。我可以帮助您解答各种问题。',
          'meeting_summary': '📝 会议纪要生成完成：\n\n## 会议要点\n1. 项目进展汇报\n2. 下阶段工作安排\n3. 资源配置讨论\n\n## 行动项\n- 完成产品原型设计\n- 技术方案评审\n- 市场调研分析',
          'professional_translate': '🌍 专业翻译结果：\n\n**原文：** ' + chatData.message + '\n\n**译文：** This is a professional translation result. The content has been accurately translated while maintaining the original meaning and professional terminology.',
          'daily_report': '📊 日报生成完成：\n\n## 今日工作总结\n✅ 完成功能开发\n✅ 代码review\n✅ 测试用例编写\n\n## 明日计划\n🎯 功能联调测试\n🎯 文档整理\n🎯 部署准备',
          'ppt_assistant': '📈 PPT大纲生成：\n\n**主题：** ' + chatData.message + '\n\n**目录结构：**\n1. 引言与背景\n2. 现状分析\n3. 解决方案\n4. 实施计划\n5. 预期效果\n6. 总结展望'
        };

        const reply = responses[chatData.chatType] || responses['general'];
        
        // 保存到模拟历史记录
        const chatRecord = {
          id: Date.now(),
          userId: chatData.userId || 1001,
          userMessage: chatData.message,
          aiResponse: reply,
          chatType: chatData.chatType || 'general',
          modelName: chatData.chatType === 'general' ? 'deepseek-chat' : 'qwen-max',
          createdAt: new Date().toISOString()
        };
        
        this.mockChatHistory.unshift(chatRecord);

        resolve({
          code: 200,
          message: '对话成功',
          data: {
            response: reply,
            chatId: chatRecord.id,
            model: chatRecord.modelName
          }
        });
      }, 800); // 模拟AI思考时间
    });
  },

  // 模拟获取聊天历史
  async getChatHistory(params) {
    return new Promise((resolve) => {
      setTimeout(() => {
        const { page = 1, size = 20 } = params;
        const start = (page - 1) * size;
        const end = start + parseInt(size);
        const list = this.mockChatHistory.slice(start, end);

        resolve({
          code: 200,
          message: '获取成功',
          data: {
            list: list,
            total: this.mockChatHistory.length,
            hasNext: end < this.mockChatHistory.length,
            hasPrevious: page > 1
          }
        });
      }, 300);
    });
  },

  // 模拟获取VIP套餐
  async getVipPlans() {
    return new Promise((resolve) => {
      setTimeout(() => {
        resolve({
          code: 200,
          message: '获取成功',
          data: [
            {
              id: 'monthly',
              name: '月度会员',
              price: 29.9,
              originalPrice: 39.9,
              features: ['无限AI对话', '专业功能使用', '优先响应速度', '历史记录保存'],
              popular: false
            },
            {
              id: 'quarterly',
              name: '季度会员',
              price: 79.9,
              originalPrice: 119.9,
              features: ['无限AI对话', '专业功能使用', '优先响应速度', '历史记录保存', '专属客服'],
              popular: true
            },
            {
              id: 'yearly',
              name: '年度会员',
              price: 199.9,
              originalPrice: 479.9,
              features: ['无限AI对话', '专业功能使用', '优先响应速度', '历史记录保存', '专属客服', '定制功能'],
              popular: false
            }
          ]
        });
      }, 300);
    });
  }
};

module.exports = localMockApi;

